package com.yuwubao.uav.tool.service.impl;

import com.yuwubao.framework.bean.PageData;
import com.yuwubao.uav.tool.mapper.OrgProjectMapper;
import com.yuwubao.uav.tool.service.OrgProjectService;
import com.yuwubao.uav.tool.util.StringUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 *
 */
@Service
public class OrgProjectServiceImpl implements OrgProjectService {

    private static final Logger logger = LogManager.getLogger(OrgProjectServiceImpl.class.getName());

    @Resource
    private OrgProjectMapper orgProjectMapper;

    @Override
    public void clickOrgProject(PageData pageData) throws Exception {
        try{
            orgProjectMapper.clickOrgProject(pageData);

        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void deleteOrgProject(PageData pageData) throws Exception {
        try{
            String ids = pageData.get("ids") == null ? "" : pageData.getString("ids");
            if (StringUtil.isNotNvlOrBlank(ids)) {
                String[] idArr = ids.split(",");
                if (idArr != null && idArr.length>0) {
                    pageData.put("idArr",idArr);
                    orgProjectMapper.deleteOrgProject(pageData);

                }
            }
        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void updateOrgProject(PageData pageData) throws Exception {
        try{
            orgProjectMapper.updateOrgProject(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void disableOrEnableOrgProject(PageData pageData) throws Exception {
        try{
            String ids = pageData.get("ids") == null ? "" : pageData.getString("ids");
            if (StringUtil.isNotNvlOrBlank(ids)) {
                String[] idArr = ids.split(",");
                if (idArr != null && idArr.length>0) {
                    pageData.put("idArr",idArr);
                    orgProjectMapper.disableOrEnableOrgProject(pageData);

                }
            }
        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void disableOrEnableOrgProjectType(PageData pageData) throws Exception {
        try{
            String ids = pageData.get("ids") == null ? "" : pageData.getString("ids");
            if (StringUtil.isNotNvlOrBlank(ids)) {
                String[] idArr = ids.split(",");
                if (idArr != null && idArr.length>0) {
                    pageData.put("idArr",idArr);
                    orgProjectMapper.disableOrEnableOrgProjectType(pageData);

                }
            }
        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void addOrgProject(PageData pageData) throws Exception {
        try{
            orgProjectMapper.addOrgProject(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
    }

    @Override
    public List<PageData> listOrgProject(PageData pageData) throws Exception {
        try{
            return orgProjectMapper.listOrgProject(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
        return null;
    }
    @Override
    public int listOrgProjectCount(PageData pageData) throws Exception {
        try{
            return orgProjectMapper.listOrgProjectCount(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
        return 0;
    }

    @Override
    public void deleteOrgProjectType(PageData pageData) throws Exception {
        try{

            String ids = pageData.get("ids") == null ? "" : pageData.getString("ids");

            if (StringUtil.isNotNvlOrBlank(ids)) {
                String[] idArr = ids.split(",");
                if (idArr != null && idArr.length>0) {
                    pageData.put("idArr",idArr);
                    orgProjectMapper.deleteOrgProjectType(pageData);

                }
            }


        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void updateOrgProjectType(PageData pageData) throws Exception {
        try{
            orgProjectMapper.updateOrgProjectType(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
    }

    @Override
    public void addOrgProjectType(PageData pageData) throws Exception {
        try{
            String names = pageData.get("names") == null ? "" : pageData.getString("names");
            if (StringUtil.isNotNvlOrBlank(names)) {
                String[] nameArr = names.split(",");
                if (nameArr != null && nameArr.length>0) {
                    for (String name : nameArr) {
                        pageData.put("name",name);
                        orgProjectMapper.addOrgProjectType(pageData);
                    }
                }
            }
        }catch (Exception e) {
            logger.debug("",e);
        }
    }

    @Override
    public List<PageData> listOrgProjectType(PageData pageData) throws Exception {
        try{
            return orgProjectMapper.listOrgProjectType(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
        return null;
    }
    @Override
    public List<PageData> listOrgProjectTypeAll(PageData pageData) throws Exception {
        try{
            return orgProjectMapper.listOrgProjectTypeAll(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
        return null;
    }
    @Override
    public int listOrgProjectTypeCount(PageData pageData) throws Exception {
        try{
            return orgProjectMapper.listOrgProjectTypeCount(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
        return 0;
    }

}
